/**
 * Copyright (c) 2019 AsHacker All rights reserved.
 *
 * http://www.ashacker.com
 *
 * 版权所有，侵权必究！
 */

package io.renren.modules.sys.redis;


import io.renren.common.utils.RedisKeys;
import io.renren.common.utils.RedisUtils;
import io.renren.modules.sys.entity.SysDataEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 系统数据字典Redis
 *
 * @author Chen chenchen@ashacker.com
 */
@Component
public class SysDataRedis {
    @Autowired
    private RedisUtils redisUtils;

    public void saveOrUpdate(SysDataEntity data) {
        if(data == null){
            return ;
        }
        String key = RedisKeys.getSysDataKey(data.getParamKey());
        redisUtils.set(key, data);
    }

    public void delete(String dataKey) {
        String key = RedisKeys.getSysDataKey(dataKey);
        redisUtils.delete(key);
    }

    public SysDataEntity get(String dataKey){
        String key = RedisKeys.getSysDataKey(dataKey);
        return redisUtils.get(key, SysDataEntity.class);
    }
}
